import 'package:flutter/material.dart';
import 'package:wallet_home/model/wallet_list_model.dart';
import 'package:wallet_home/page/theme/colors.dart';
import 'package:wallet_home/tools/theme_utils.dart';
import '../../module_config.dart';
import '../model/search_model.dart';

class ListViewItem extends StatefulWidget {
  final CoinsBean itemModel;
  final VoidCallback onTap;

  ListViewItem(this.itemModel, this.onTap);

  @override
  ListViewItemState createState() => ListViewItemState();
}

class ListViewItemState extends State<ListViewItem> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      child: Container(
        height: 60,
        child: _content(),
      ),
      onTap: () {
        widget.itemModel.isSelected = !widget.itemModel.isSelected;
        widget.onTap();
        setState(() {});
      },
    );
  }

  Widget _content() {
    return Container(
      height: 43,
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[_left(), _middle(), _right()],
      ),
    );
  }

  Widget _left() {
    return Container(
//      decoration: BoxDecoration(
//          border: Border.all(
//              color: Color(0xfff4f4f4), width: 1, style: BorderStyle.solid),
//          borderRadius: BorderRadius.circular(14.0)),
      margin: EdgeInsets.only(top: 8, left: 8, bottom: 7, right: 8),
      child: Image.asset(
        widget.itemModel.img,
        package: ModuleConfig.moduleName,
        width: 30,
        height: 30,
        fit: BoxFit.cover,
      ),
    );
  }

  Widget _middle() {
    return Expanded(
      child: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
                margin: EdgeInsets.only(bottom: 2),
                child: Text("${widget.itemModel.title}",
                    style: TextStyle(
                      fontSize: 14,
                      color: ThemeUtils.getThemeColor(
                          context: context,
                          brightnessColor: Colors.grey[800],
                          darkColor: Colors.grey[50]),
                    ))),
            Container(
                margin: EdgeInsets.only(top: 1),
                child: Text("${widget.itemModel.coinid}",
                    style: TextStyle(
                      fontSize: 12,
                      color: ThemeUtils.getThemeColor(
                          context: context,
                          brightnessColor: Colors.grey[800],
                          darkColor: Colors.grey[50]),
                    ))),
          ],
        ),
      ),
    );
  }

  Widget _right() {
    return Container(
      margin: EdgeInsets.only(top: 12, right: 12, bottom: 11, left: 12),
      child: widget.itemModel.isSelected
          ? Image.asset("assets/images/coin_check_icon.png",
              color: ThemeUtils.getThemeColor(
                  context: context,
                  brightnessColor: Colours.app_main,
                  darkColor: Colours.color_gold),
              package: ModuleConfig.moduleName)
          : Image.asset("assets/images/coin_cancel_icon.png",
              package: ModuleConfig.moduleName),
    );
  }
}
